/*
 * SongTransferable.java
 *
 * Created on September 15, 2006, 2:24 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.bff.slimserver.music;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.bff.slimserver.musicobjects.SlimPlayableObject;

/**
 *
 * @author bfindeisen
 */
public class SongTransferable implements Transferable, ClipboardOwner {

    private SlimPlayableObject object;
    public static final DataFlavor objectFlavor = new DataFlavor(org.bff.slimserver.musicobjects.SlimPlayableObject.class,
            "Non local Song");
    public static final DataFlavor localObjectFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType
            + "; class=org.bff.slimserver.musicobjects.SlimPlayableObject",
            "Local Song");
    public static final DataFlavor[] flavors = {
        objectFlavor,
        localObjectFlavor
    };
    private static final List flavorList = Arrays.asList(flavors);

    /** Creates a new instance of SongTransferable */
    public SongTransferable(SlimPlayableObject object) {
        this.object = object;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return (flavors);
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return (flavorList.contains(flavor));
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (flavor.equals(objectFlavor)) {
            return (this.object);
        } else if (flavor.equals(localObjectFlavor)) {
            return this.object;

        } else if (flavor.equals(DataFlavor.stringFlavor)) {
            return (this.object.getName());
        } else {
            throw new UnsupportedFlavorException(flavor);
        }
    }

    @Override
    public void lostOwnership(Clipboard clipboard, Transferable contents) {
    }
}
